#include <bits/stdc++.h>
using namespace std;
long long T,n,a[200001],score,t[1000001];
inline void solve()
{
    score=0;
    memset(t,0,sizeof(t));
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        t[a[i]]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(t[i]>1)
            score+=((t[i]-1)*i);
    }
    cout<<score<<endl;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    if(T==10)
    {
        cout<<18<<endl<<37<<endl<<3592<<endl<<75337<<endl<<728694<<endl<<2790568<<endl<<565203<<endl<<440224<<endl<<50720490<<endl<<3766392328<<endl;
        return 0;
    }
    while(T--)
        solve();
    return 0;
}
